﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace ViewModel.Finance
{
    /// <summary>
    /// This class is the viewmodel for the finance section.
    /// </summary>
    public class SectionViewModel : SectionWorkspaceViewModel
    {
        private TheBudgetViewModel theBudgetViewModel;
        private BudgetItemsListViewModel budgetItemsListView;
        private FrequencyListViewModel frequencyListViewMode;
        private CategoryListViewModel categoryListViewMode;
        private BalanceTypeListViewModel balanceTypeListViewModel;
        private SavingsPlansListViewModel savingsPlansListViewModel;

        public SectionViewModel(MainWindowViewModel mainWindowViewModel)
        {
            if (mainWindowViewModel == null) throw new ArgumentNullException();

            this.MainWindowViewModel = mainWindowViewModel;
        }

        public override ReadOnlyCollection<CommandViewModel> Commands
        {
            get
            {
                if (_commands == null)
                {
                    List<CommandViewModel> cmds = CreateFeatureCommands();
                    _commands = new ReadOnlyCollection<CommandViewModel>(cmds);
                }
                return _commands;
            }
        }

        private List<CommandViewModel> CreateFeatureCommands()
        {
            return new List<CommandViewModel>
                       {
                           new CommandViewModel( "The Budget", new RelayCommand(param => ShowBudgetItemsList2())),
                           new CommandViewModel( "Savings Plans", new RelayCommand(param => ShowScheduledItemsList())),
                           new CommandViewModel( "Bills", new RelayCommand(param => ShowBillsList())),
                           new CommandViewModel( "Categories", new RelayCommand(param => ShowCategoryList())),
                           new CommandViewModel( "Frequencies", new RelayCommand(param => ShowFrequencyList())),
                           new CommandViewModel( "Balance Types", new RelayCommand(param => ShowBalanceTypeList()))
                       };
        }

        private void ShowBudgetItemsList2()
        {
            if (budgetItemsListView == null)
            {
                budgetItemsListView = new BudgetItemsListViewModel();
            }
            MainWindowViewModel.ShowWorkspace(budgetItemsListView);
        }

        private void ShowBalanceTypeList()
        {
            if (balanceTypeListViewModel == null)
            {
                balanceTypeListViewModel = new BalanceTypeListViewModel();
            }
            MainWindowViewModel.ShowWorkspace(balanceTypeListViewModel);
        }

        private void ShowCategoryList()
        {
            if (categoryListViewMode == null)
            {
                categoryListViewMode = new CategoryListViewModel();
            }
            MainWindowViewModel.ShowWorkspace(categoryListViewMode);
        }

        private void ShowFrequencyList()
        {
            if(frequencyListViewMode == null)
            {
                frequencyListViewMode = new FrequencyListViewModel();
            }
            MainWindowViewModel.ShowWorkspace(frequencyListViewMode);
        }

        private void ShowBillsList()
        {
        }

        private void ShowScheduledItemsList()
        {
            if(savingsPlansListViewModel == null)
            {
                savingsPlansListViewModel = new SavingsPlansListViewModel();
            }
            MainWindowViewModel.ShowWorkspace(savingsPlansListViewModel);
        }

        private void ShowBudgetItemsList()
        {
            if (theBudgetViewModel == null)
            {
                theBudgetViewModel = new TheBudgetViewModel();
            }
            MainWindowViewModel.ShowWorkspace(theBudgetViewModel);
        }

    }
}